import { baseApiUrl, path } from "../../utils/config";
import { productIndex } from '../../utils/api';
const app = getApp();
Page({
  data: {
    baseImageUrl: baseApiUrl,
    name: "",
    rotation: [],
    news: [],
    class_three: [],
    class_six: [],

    scene_show: [],
    last_show: {},
    list: []
  },
  onLoad(options) {
    this.getList();
  },
  async getList() {
    let { name } = this.data;
    let res = await productIndex({ name });
    let { rotation, class_three, class_six, scene_show, last_show, last_show_product } = res;
    let news = res.new;

    // export function groupList(array, len) {
    //   let index = 0;
    //   const newArray = [];
    //   while (index < array.length) {
    //     newArray.push(array.slice(index, (index += len)));
    //   }
    //   return newArray;
    // }
    const list = [];
    let index = 0;
    while (index < last_show_product.length) {
      list.push(last_show_product.slice(index, (index += 2)));
    };
    this.setData({ rotation, news, class_three, class_six, scene_show, last_show, list })
  },
  router(e) {
    let { url } = e.currentTarget.dataset;
    wx.navigateTo({ url })
  },
  onShareAppMessage() {
    let poster = app.globalData.poster;
    return {
      path,
      imageUrl: poster
    }
  },
  onShareTimeline() { }
})